package com.allwees.bs.configuration;

import com.allwees.bs.core.model.logistics.entity.LogisticsModel;
import com.allwees.bs.core.model.merchant.entity.MerchantModel;
import com.allwees.bs.core.model.merchant.entity.StoreModel;
import com.allwees.bs.core.model.order.entity.OrderModel;
import com.allwees.bs.core.model.order.entity.SkuSnapModel;
import com.allwees.bs.core.model.user.entity.UserModel;
import com.allwees.bs.module.core.dynamic.core.DynamicInjectAspect;
import com.allwees.bs.module.core.dynamic.data.DynamicInjectQuery;
import com.allwees.bs.module.lms.dao.LogisticsDao;
import com.allwees.bs.module.mms.dao.RetailerDao;
import com.allwees.bs.module.mms.dao.StoreDao;
import com.allwees.bs.module.oms.dao.OmsOrderDao;
import com.allwees.bs.module.oms.dao.OrderSkuSnapDao;
import com.allwees.bs.module.pms.service.CategoryService;
import com.allwees.bs.module.ums.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DynamicInjectConfiguration {

    @Autowired
    private OrderSkuSnapDao orderSkuSnapDao;
    @Autowired
    private RetailerDao retailerDao;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private StoreDao storeDao;
    @Autowired
    private LogisticsDao logisticsDao;
    @Autowired
    private OmsOrderDao omsOrderDao;

    @Autowired
    private CustomerService customerService;


    @Bean
    public DynamicInjectQuery dynamicInjectQuery() {
        return new DynamicInjectQuery() {
            @Override
            public SkuSnapModel findSkuSnapByKey(String key) {
                return orderSkuSnapDao.findByOrderItemUuid(key);
            }

            @Override
            public StoreModel findStoreByKey(String key) {
                return storeDao.findByUuid(key);
            }

            @Override
            public MerchantModel findRetailerByKey(String key) {
                return retailerDao.findByUuid(key);
            }

            @Override
            public String findCategoryFullname(String key) {
                return categoryService.getFullname(key);
            }

            @Override
            public LogisticsModel findLogisticsByKey(String key) {
                return logisticsDao.findByUuid(key);
            }

            @Override
            public OrderModel findShippingAddressByKey(String key) {
                return omsOrderDao.findByUuid(key);
            }

            @Override
            public UserModel findUserByKey(String key) {
                return  customerService.findByUuid(key);
            }
        };
    }

    @Bean
    public DynamicInjectAspect dynamicInjectAspect(DynamicInjectQuery dynamicInjectQuery) {
        DynamicInjectAspect dynamicInjectAspect = new DynamicInjectAspect();
        dynamicInjectAspect.setDynamicInjectQuery(dynamicInjectQuery);
        return dynamicInjectAspect;
    }
}
